package com.example.leaderapplication.View.Activity.BanCi;

import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.TimePicker;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.leaderapplication.Base.BaseActivity;
import com.example.leaderapplication.Base.BaseConfig;
import com.example.leaderapplication.Bean.AddShiftsInfoRequsetBean;
import com.example.leaderapplication.Bean.FindShiftsDetailInfoRequestBean;
import com.example.leaderapplication.Bean.FindShiftsDetailInfoResultBean;
import com.example.leaderapplication.Bean.FindShipListResultBean;
import com.example.leaderapplication.Bean.FindShipRouteListRequestBean;
import com.example.leaderapplication.Bean.FindShipRouteListResultBean;
import com.example.leaderapplication.Bean.UpdateShiftsInfoRequestBean;
import com.example.leaderapplication.Bean.UpdateShiftsInfoResultBean;
import com.example.leaderapplication.R;
import com.example.leaderapplication.RetrufitHelp.BaseSubscriber;
import com.example.leaderapplication.RetrufitHelp.ExceptionHandle;
import com.example.leaderapplication.RetrufitHelp.RetrofitClient;
import com.example.leaderapplication.Utils.SPUtil;
import com.example.leaderapplication.Utils.StringUtil;
import com.example.leaderapplication.Utils.TimeUtil;
import com.example.leaderapplication.Utils.ToastUtil;
import com.example.leaderapplication.Widgets.CustomFindShipRouteListWindow;
import com.example.leaderapplication.Widgets.CustomShipListShowWindow;
import com.example.leaderapplication.Widgets.CustomTimePickWindow;
import com.example.leaderapplication.Widgets.DatePicker;
import com.wuhenzhizao.titlebar.widget.CommonTitleBar;

import java.util.ArrayList;
import java.util.List;

public class ChangeBanCiActivity extends BaseActivity {

    private CommonTitleBar commonTitleBar;
    private LinearLayout llLineSelete;
    private LinearLayout llShipSelete;
    private LinearLayout llShipOutBegin;
    private LinearLayout llShipOutEnd;
    private LinearLayout llBeginDate;
    private LinearLayout llEndDate;
    //    private LinearLayout llNoTimeBegin;
//    private LinearLayout llNoTimeEnd;
    private String businessOrgId;
    private FindShipRouteListRequestBean findShipRouteListRequestBean;
    private List<FindShipRouteListResultBean.DataBean> shiftDataList;
    private CustomFindShipRouteListWindow popupWindow;
    private CustomShipListShowWindow shipPopupWindow;
    private TextView lineName;
    private TextView unitName;
    private TextView lineNumber;
    private TextView pointName;
    private TextView projectName;
    private TextView wharfOut;
    private TextView wharfIn;
    private TextView shipName;
    private TextView havePeople;
    private TextView beginTime;
    private TextView beginTimeTitle;
    private TextView endTime;
    private TextView beginData;
    private TextView endData;
    private TextView noTimeAdd;
    private TextView noTimeBegin;
    private TextView noTimeEnd;
    private TextView etCause;
    private Button saveShip;
    private List<FindShipListResultBean.DataBean> shipDataList;
    private CheckBox cbStatic;
    private CheckBox cbDriven;
    private CustomTimePickWindow timePickWindow;

    private int beginHour = 0;
    private int beginMinute = 0;

    private int endHour = 23;
    private int endMinute = 59;
    private EditText advanceCheck;
    private EditText stopCheck;

    private EditText inventoryShip;
    private EditText inventoryShipName;
    private EditText inventoryShipNumber;

    private String startDate;
    private String endDate;

    private String startNoDate;
    private String endNoDate;

//    private CheckBox cbOne;
//    private CheckBox cbTwo;
//    private CheckBox cbThree;
//    private CheckBox cbFour;
//    private CheckBox cbFive;
//    private CheckBox cbSix;
//    private CheckBox cbSeven;

    private List<String> weekSelete = new ArrayList<>();

    private List<AddShiftsInfoRequsetBean.LimitDateListBean> noTimeData;
    private CheckBox cbNormal;
    private CheckBox cbStop;
    //添加班次
//    private AddShiftsInfoRequsetBean addShiftsInfoRequsetBean;
    //修改班次
    private FindShiftsDetailInfoRequestBean infoRequestBean;
    private Long shiftsId;
    private UpdateShiftsInfoRequestBean shiftsInfoRequestBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        commonTitleBar = findViewById(R.id.add_title_bar_ban_ci_add);
        commonTitleBar.setListener(new CommonTitleBar.OnTitleBarListener() {
            @Override
            public void onClicked(View v, int action, String extra) {
                if (action == CommonTitleBar.ACTION_LEFT_TEXT) {
                    finish();
                }
            }
        });


    }

    @Override
    public int setLayoutId() {
        return R.layout.activity_change_ban_ci;
    }

    @Override
    protected void initView() {

        if (shiftDataList == null) {
            shiftDataList = new ArrayList<>();
        }
        if (shipDataList == null) {
            shipDataList = new ArrayList<>();
        }

        if (noTimeData == null) {
            noTimeData = new ArrayList<>();
        }

//        if (addShiftsInfoRequsetBean == null) {
//            addShiftsInfoRequsetBean = new AddShiftsInfoRequsetBean();
//        }

        if (shiftsInfoRequestBean == null) {
            shiftsInfoRequestBean = new UpdateShiftsInfoRequestBean();
        }

        lineName = findViewById(R.id.tv_add_banci_line_name);
        unitName = findViewById(R.id.tv_add_banci_unit_name);
        lineNumber = findViewById(R.id.tv_add_banci_line_number);
        pointName = findViewById(R.id.tv_add_banci_point_name);
        projectName = findViewById(R.id.tv_add_banci_project_name);
        wharfOut = findViewById(R.id.tv_add_banci_wharf_out);
        wharfIn = findViewById(R.id.tv_add_banci_wharf_in);
        shipName = findViewById(R.id.tv_add_banci_ship_name);
        havePeople = findViewById(R.id.tv_add_banci_ship_have_people);
        beginTime = findViewById(R.id.tv_add_banci_begin_time);
        beginTimeTitle = findViewById(R.id.tv_add_banci_out_time_begin_title);
        endTime = findViewById(R.id.tv_add_banci_end_time);
        beginData = findViewById(R.id.tv_add_banci_begin_data);
        endData = findViewById(R.id.tv_add_banci_end_data);
        noTimeAdd = findViewById(R.id.tv_add_banci_no_time);
        noTimeBegin = findViewById(R.id.tv_add_banci_no_time_begin);
        noTimeEnd = findViewById(R.id.tv_add_banci_no_time_end);
        etCause = findViewById(R.id.et_add_banci_cause);

        saveShip = findViewById(R.id.bt_add_banci_save);

//        cbOne = findViewById(R.id.cb_add_banci_one);
//        cbTwo = findViewById(R.id.cb_add_banci_two);
//        cbThree = findViewById(R.id.cb_add_banci_three);
//        cbFour = findViewById(R.id.cb_add_banci_four);
//        cbFive = findViewById(R.id.cb_add_banci_five);
//        cbSix = findViewById(R.id.cb_add_banci_six);
//        cbSeven = findViewById(R.id.cb_add_banci_seven);

        advanceCheck = findViewById(R.id.et_add_banci_advance_check);
        stopCheck = findViewById(R.id.et_add_banci_stop_check);

        inventoryShip = findViewById(R.id.et_add_banci_inventory_ship);
        inventoryShipName = findViewById(R.id.et_add_banci_inventory_ship_name);
        inventoryShipNumber = findViewById(R.id.et_add_banci_inventory_ship_number);

        cbStatic = findViewById(R.id.cb_add_banci_static);
        cbDriven = findViewById(R.id.cb_add_banci_driven);

        cbNormal = findViewById(R.id.cb_add_banci_normal);
        cbStop = findViewById(R.id.cb_add_banci_stop);

        //显示无效时段
//        rlNoTimeShow = findViewById(R.id.rl_add_ban_ci_no_time);
//        rlNoTimeShow.setLayoutManager(new LinearLayoutManager(ChangeBanCiActivity.this, RecyclerView.VERTICAL, false));
//        banCiNoTimeListAdapter = new BanCiNoTimeListAdapter(ChangeBanCiActivity.this, noTimeData);
//        rlNoTimeShow.setAdapter(banCiNoTimeListAdapter);
//
//        rlNoTimeShow.setVisibility(View.GONE);

        //获取景区 businessOrgId 为请求
        findShipRouteListRequestBean = new FindShipRouteListRequestBean();
        businessOrgId = (String) SPUtil.get(ChangeBanCiActivity.this, BaseConfig.BUSINESS_ORG_ID, "");
        findShipRouteListRequestBean.setBusinessOrgId(businessOrgId);

        llLineSelete = findViewById(R.id.ll_add_ban_ci_line_name);
        llShipSelete = findViewById(R.id.ll_add_banci_ship_name);
        llShipOutBegin = findViewById(R.id.ll_add_banci_out_time_begin);
        llShipOutEnd = findViewById(R.id.ll_add_banci_out_time_end);
        llBeginDate = findViewById(R.id.ll_add_banci_begin_date);
        llEndDate = findViewById(R.id.ll_add_banci_end_date);
//        llNoTimeBegin = findViewById(R.id.ll_add_banci_no_time_begin);
//        llNoTimeEnd = findViewById(R.id.ll_add_banci_no_time_end);

        cbStatic.setChecked(true);
        cbDriven.setChecked(false);
//        addShiftsInfoRequsetBean.setLeaveTimeType(1);
        cbNormal.setChecked(true);
        cbStop.setChecked(false);
//        addShiftsInfoRequsetBean.setFlag(2);
        llShipOutEnd.setVisibility(View.GONE);

        //修改数据，要通过详情接口获取数据
        shiftsId = getIntent().getLongExtra("shiftsId", 0L);
        if (infoRequestBean == null) {
            infoRequestBean = new FindShiftsDetailInfoRequestBean();
        }
        infoRequestBean.setShiftsId(shiftsId);
        findShiftsDetailInfo();
    }

    private void findShiftsDetailInfo() {
        RetrofitClient.getInstance(ChangeBanCiActivity.this, baseUrl, headers).findShiftsDetailInfo(infoRequestBean, new BaseSubscriber<FindShiftsDetailInfoResultBean>(ChangeBanCiActivity.this) {
            @Override
            public void onError(ExceptionHandle.ResponeThrowable e) {
                ToastUtil.showToast(e.message);
            }

            @Override
            public void onNext(FindShiftsDetailInfoResultBean findShiftsDetailInfoResultBean) {
                if (findShiftsDetailInfoResultBean.getCode().equals("200")) {
                    // 有数据，那么就去赋值
                    lineName.setText(findShiftsDetailInfoResultBean.getData().getRouteName());
                    unitName.setText(findShiftsDetailInfoResultBean.getData().getBusinessOrgShortName());
                    lineNumber.setText(findShiftsDetailInfoResultBean.getData().getRouteNo() + "");
                    pointName.setText(findShiftsDetailInfoResultBean.getData().getScenicSpotsName());
                    projectName.setText(findShiftsDetailInfoResultBean.getData().getProjectShortName());
                    wharfOut.setText(findShiftsDetailInfoResultBean.getData().getLeavePointName());
                    wharfIn.setText(findShiftsDetailInfoResultBean.getData().getArrivePointName());
                    shipName.setText(findShiftsDetailInfoResultBean.getData().getShipName());
                    havePeople.setText(findShiftsDetailInfoResultBean.getData().getShipCapacity() + "");

                    String leaveTime = findShiftsDetailInfoResultBean.getData().getLeaveTime();

                    if (findShiftsDetailInfoResultBean.getData().getLeaveTimeType() == 1) {
                        cbStatic.setChecked(true);
                        cbDriven.setChecked(false);
                        llShipOutEnd.setVisibility(View.GONE);
                        beginTimeTitle.setText("时间:");
                        beginTime.setText(leaveTime + "");
                    } else {
                        cbStatic.setChecked(false);
                        cbDriven.setChecked(true);
                        llShipOutEnd.setVisibility(View.VISIBLE);
                        beginTimeTitle.setText("开始时间:");
                        String[] split = leaveTime.split("-");
                        beginTime.setText(split[0] + "");
                        endTime.setText(split[1] + "");

                    }

                    cbStatic.setClickable(false);
                    cbDriven.setClickable(false);


                    advanceCheck.setText(findShiftsDetailInfoResultBean.getData().getAdvanceTime() + "");
                    stopCheck.setText(findShiftsDetailInfoResultBean.getData().getStopSellTime() + "");
                    inventoryShip.setText(findShiftsDetailInfoResultBean.getData().getShiftsCapacity() + "");
                    inventoryShipName.setText(findShiftsDetailInfoResultBean.getData().getShiftsName());
                    inventoryShipNumber.setText(findShiftsDetailInfoResultBean.getData().getShiftsNo() + "");

                    inventoryShipNumber.setFocusable(false);


//                    beginData.setText("");
//                    endData.setText("");

                    int flag = findShiftsDetailInfoResultBean.getData().getFlag();
                    if (flag == 1) {
                        cbNormal.setChecked(true);
                        cbStop.setChecked(false);
                    } else {
                        cbNormal.setChecked(false);
                        cbStop.setChecked(true);
                    }
                    etCause.setText(findShiftsDetailInfoResultBean.getData().getSuspendReason());

                    //给更改请求数据赋值
                    shiftsInfoRequestBean.setShiftsId(findShiftsDetailInfoResultBean.getData().getShiftsId());
                    shiftsInfoRequestBean.setShiftsDate(findShiftsDetailInfoResultBean.getData().getShiftsDate());
                    shiftsInfoRequestBean.setLeaveTime(findShiftsDetailInfoResultBean.getData().getLeaveTime());
                    shiftsInfoRequestBean.setShiftsCapacity(findShiftsDetailInfoResultBean.getData().getShiftsCapacity());
                    shiftsInfoRequestBean.setShipIdStr(findShiftsDetailInfoResultBean.getData().getShipIdStr());
                    shiftsInfoRequestBean.setShiftsName(findShiftsDetailInfoResultBean.getData().getShiftsName());
                    shiftsInfoRequestBean.setShiftsNo(findShiftsDetailInfoResultBean.getData().getShiftsNo());
                    shiftsInfoRequestBean.setShiftsNature(findShiftsDetailInfoResultBean.getData().getShiftsNature());
                    shiftsInfoRequestBean.setAdvanceTime(findShiftsDetailInfoResultBean.getData().getAdvanceTime());
                    shiftsInfoRequestBean.setStopSellTime(findShiftsDetailInfoResultBean.getData().getStopSellTime());
                    shiftsInfoRequestBean.setFlag(findShiftsDetailInfoResultBean.getData().getFlag());
                    shiftsInfoRequestBean.setBusinessOrgId(findShiftsDetailInfoResultBean.getData().getBusinessOrgId());
                    shiftsInfoRequestBean.setScenicSpotsId(findShiftsDetailInfoResultBean.getData().getScenicSpotsId());

                } else {
                    ToastUtil.showToast(findShiftsDetailInfoResultBean.getMessage());
                }

            }
        });
    }

    @Override
    protected void doSomeThing() {


//        llLineSelete.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                llLineSelete.setClickable(false);
//                findShipRouteList();
//
//            }
//        });

        llShipSelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                llShipSelete.setClickable(false);
                findShipList();
            }
        });

        cbStatic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                addShiftsInfoRequsetBean.setLeaveTimeType(1);
                cbStatic.setChecked(true);
                cbDriven.setChecked(false);
                beginTimeTitle.setText("时间:");
                llShipOutEnd.setVisibility(View.GONE);
//                addShiftsInfoRequsetBean.setLeaveTime(beginTime.getText().toString());
            }
        });

        cbDriven.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                addShiftsInfoRequsetBean.setLeaveTimeType(2);
                cbStatic.setChecked(false);
                cbDriven.setChecked(true);
                beginTimeTitle.setText("开始时间:");
                llShipOutEnd.setVisibility(View.VISIBLE);
//                addShiftsInfoRequsetBean.setLeaveTime(beginTime.getText().toString() + "-" + endTime.getText().toString());
            }
        });

//        llShipOutBegin.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showTimeBegin();
//            }
//        });
//
//        llShipOutEnd.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                showTimeEnd();
//            }
//        });

        advanceCheck.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (!StringUtil.isNullOrEmpty(advanceCheck.getText().toString())) {
//                    addShiftsInfoRequsetBean.setAdvanceTime(Integer.parseInt(advanceCheck.getText().toString()));
                    shiftsInfoRequestBean.setAdvanceTime(Integer.parseInt(advanceCheck.getText().toString()));
                }
            }
        });

        stopCheck.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (!StringUtil.isNullOrEmpty(stopCheck.getText().toString())) {
//                    addShiftsInfoRequsetBean.setStopSellTime(Integer.parseInt(stopCheck.getText().toString()));
                    shiftsInfoRequestBean.setStopSellTime(Integer.parseInt(stopCheck.getText().toString()));
                }
            }
        });

        inventoryShip.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (!StringUtil.isNullOrEmpty(inventoryShip.getText().toString())) {
//                    addShiftsInfoRequsetBean.setShiftsCapacity(Integer.parseInt(inventoryShip.getText().toString()));
                    shiftsInfoRequestBean.setShiftsCapacity(Integer.parseInt(inventoryShip.getText().toString()));
                }
            }
        });

        inventoryShipName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (!StringUtil.isNullOrEmpty(inventoryShipName.getText().toString())) {
//                    addShiftsInfoRequsetBean.setShiftsName(inventoryShipName.getText().toString());
                    shiftsInfoRequestBean.setShiftsName(inventoryShipName.getText().toString());
                }
            }
        });


        llBeginDate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showdata("begin");
            }
        });

        llEndDate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showdata("end");
            }
        });

        cbNormal.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                addShiftsInfoRequsetBean.setFlag(1);
                shiftsInfoRequestBean.setFlag(1);
                cbNormal.setChecked(true);
                cbStop.setChecked(false);
            }
        });

        cbStop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                addShiftsInfoRequsetBean.setFlag(2);
                shiftsInfoRequestBean.setFlag(2);
                cbNormal.setChecked(false);
                cbStop.setChecked(true);
            }
        });


        etCause.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (!StringUtil.isNullOrEmpty(etCause.getText().toString())) {
//                    addShiftsInfoRequsetBean.setSuspendReason(etCause.getText().toString());
                    shiftsInfoRequestBean.setSuspendReason(etCause.getText().toString());
                }
            }
        });

        saveShip.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //这里准备数据，然后 直接去请求
                if (shiftsInfoRequestBean.getShipIdStr() == null) {
                    ToastUtil.showToast("请选择游船名称");
                    return;
                }


                if (shiftsInfoRequestBean.getAdvanceTime() == 0) {
                    ToastUtil.showToast("请填写提前检票时间");
                    return;
                }

                if (shiftsInfoRequestBean.getStopSellTime() == 0) {
                    ToastUtil.showToast("请填写停止售票时间");
                    return;
                }
                if (shiftsInfoRequestBean.getShiftsCapacity() == 0) {
                    ToastUtil.showToast("请填写班次库存");
                    return;
                }

                if (shiftsInfoRequestBean.getShiftsName() == null) {
                    ToastUtil.showToast("请填写班次名称");
                    return;
                }

//                addShiftsInfo();
                //去修改班次信息
                updateShiftsInfo();
            }
        });
    }

    private void updateShiftsInfo() {
        RetrofitClient.getInstance(ChangeBanCiActivity.this, baseUrl, headers).updateShiftsInfo(shiftsInfoRequestBean, new BaseSubscriber<UpdateShiftsInfoResultBean>(ChangeBanCiActivity.this) {
            @Override
            public void onError(ExceptionHandle.ResponeThrowable e) {
                ToastUtil.showToast(e.message);
            }

            @Override
            public void onNext(UpdateShiftsInfoResultBean updateShiftsInfoResultBean) {
                ToastUtil.showToast(updateShiftsInfoResultBean.getMessage());

            }
        });

    }

    // 保存添加的班次
//    private void addShiftsInfo() {
//        RetrofitClient.getInstance(ChangeBanCiActivity.this, baseUrl, headers).addShiftsInfo(addShiftsInfoRequsetBean, new BaseSubscriber<AddShiftsInfoResultBean>(ChangeBanCiActivity.this) {
//            @Override
//            public void onError(ExceptionHandle.ResponeThrowable e) {
//                ToastUtil.showToast(e.message);
//            }
//
//            @Override
//            public void onNext(AddShiftsInfoResultBean addShiftsInfoResultBean) {
//                if (addShiftsInfoResultBean.getCode().equals("200")) {
//                    ToastUtil.showToast(addShiftsInfoResultBean.getMessage());
//                } else {
//                    ToastUtil.showToast(addShiftsInfoResultBean.getMessage());
//                }
//            }
//        });
//    }


    private void findShipList() {
        RetrofitClient.getInstance(ChangeBanCiActivity.this, baseUrl, headers).findShipList(findShipRouteListRequestBean, new BaseSubscriber<FindShipListResultBean>(ChangeBanCiActivity.this) {
            @Override
            public void onError(ExceptionHandle.ResponeThrowable e) {
                llShipSelete.setClickable(true);
                ToastUtil.showToast(e.message);
            }

            @Override
            public void onNext(FindShipListResultBean findShipListResultBean) {
                llShipSelete.setClickable(true);
                if (findShipListResultBean.getCode().equals("200")) {
                    if (findShipListResultBean.getData() != null && findShipListResultBean.getData().size() > 0) {
                        shipDataList.clear();
                        shipDataList.addAll(findShipListResultBean.getData());
                        showShipBotton(shipDataList);
                    } else {
                        ToastUtil.showToast("游船列表为空，请检查数据内容");
                    }

                }
            }
        });
    }


    private void findShipRouteList() {
        RetrofitClient.getInstance(ChangeBanCiActivity.this, baseUrl, headers).findShipRouteList(findShipRouteListRequestBean, new BaseSubscriber<FindShipRouteListResultBean>(ChangeBanCiActivity.this) {
            @Override
            public void onError(ExceptionHandle.ResponeThrowable e) {
                llLineSelete.setClickable(true);
                ToastUtil.showToast(e.message);
            }

            @Override
            public void onNext(FindShipRouteListResultBean findShiftsListResultBean) {
                llLineSelete.setClickable(true);
                if (findShiftsListResultBean.getCode().equals("200")) {
                    shiftDataList.clear();
                    shiftDataList.addAll(findShiftsListResultBean.getData());
                    // 获取到数据后，再去显示底部弹出框
                    if (shiftDataList != null && shiftDataList.size() > 0) {
                        showDateSelete(shiftDataList);
                    } else {
                        ToastUtil.showToast("航线列表为空，请检查数据内容");
                    }

                } else {
                    ToastUtil.showToast(findShiftsListResultBean.getMessage());
                }

            }
        });
    }

    // 游船名称列表
    private void showShipBotton(List<FindShipListResultBean.DataBean> shipDataList) {

        shipPopupWindow = new CustomShipListShowWindow(ChangeBanCiActivity.this, shipDataList, new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                shipName.setText(shipDataList.get(position).getShipName());
                havePeople.setText(shipDataList.get(position).getShipCapacity() + "");
//                addShiftsInfoRequsetBean.setShipIdStr(shipDataList.get(position).getShipId() + "");
                shiftsInfoRequestBean.setShipIdStr(shipDataList.get(position).getShipId() + "");
                shipPopupWindow.dismiss();
            }
        });

        shipPopupWindow.showAtLocation(llShipSelete, Gravity.BOTTOM | Gravity.CENTER_VERTICAL, 0, 0);

        shipPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                shipPopupWindow.backgroundAlpha(ChangeBanCiActivity.this, 1f);
            }
        });
    }

    //
    private void showTimeBegin() {

        timePickWindow = new CustomTimePickWindow(ChangeBanCiActivity.this, new TimePicker.OnTimeChangedListener() {
            @Override
            public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
                beginHour = hourOfDay;
                beginMinute = minute;

                if (beginHour > endHour) {
                    ToastUtil.showToast("开始时间必须小于结束时间");
                    beginTime.setText("");
                    return;
                } else if (beginHour == endHour) {
                    if (beginMinute > endMinute) {
                        ToastUtil.showToast("开始时间必须小于结束时间");
                        beginTime.setText("");
                        return;
                    }
                }
                String hour = "";
                String minut = "";
                if (hourOfDay < 10) {
                    hour = "0" + hourOfDay;
                } else {
                    hour = hourOfDay + "";
                }

                if (minute < 10) {
                    minut = "0" + minute;
                } else {
                    minut = minute + "";
                }
                beginTime.setText(hour + ":" + minut);

//                addShiftsInfoRequsetBean.setLeaveTime(beginTime.getText().toString());
            }
        });

        timePickWindow.showAtLocation(llLineSelete, Gravity.BOTTOM | Gravity.CENTER_VERTICAL, 0, 0);

        timePickWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                timePickWindow.backgroundAlpha(ChangeBanCiActivity.this, 1f);
            }
        });

    }

    private void showTimeEnd() {

        timePickWindow = new CustomTimePickWindow(ChangeBanCiActivity.this, new TimePicker.OnTimeChangedListener() {
            @Override
            public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
                endHour = hourOfDay;
                endMinute = minute;

                if (beginHour > endHour) {
                    ToastUtil.showToast("开始时间必须小于结束时间");
                    endTime.setText("");
                    return;
                } else if (beginHour == endHour) {
                    if (beginMinute > endMinute) {
                        ToastUtil.showToast("开始时间必须小于结束时间");
                        endTime.setText("");
                        return;
                    }
                }

                String hour = "";
                String minut = "";
                if (hourOfDay < 10) {
                    hour = "0" + hourOfDay;
                } else {
                    hour = hourOfDay + "";
                }

                if (minute < 10) {
                    minut = "0" + minute;
                } else {
                    minut = minute + "";
                }
                endTime.setText(hour + ":" + minut);

//                addShiftsInfoRequsetBean.setLeaveTime(beginTime.getText().toString() + "-" + endTime.getText().toString());
            }
        });

        timePickWindow.showAtLocation(llLineSelete, Gravity.BOTTOM | Gravity.CENTER_VERTICAL, 0, 0);

        timePickWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                timePickWindow.backgroundAlpha(ChangeBanCiActivity.this, 1f);
            }
        });

    }


    // 航线列表显示
    private void showDateSelete(List<FindShipRouteListResultBean.DataBean> shiftDataList) {

        popupWindow = new CustomFindShipRouteListWindow(ChangeBanCiActivity.this, shiftDataList, new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                lineName.setText(shiftDataList.get(position).getRouteName());
                unitName.setText(shiftDataList.get(position).getBusinessOrgShortName());
                lineNumber.setText(shiftDataList.get(position).getRouteId() + "");
                pointName.setText(shiftDataList.get(position).getScenicSpotsName() + "");
                projectName.setText(shiftDataList.get(position).getProjectShortName() + "");
                wharfOut.setText(shiftDataList.get(position).getLeaveShipDockName() + "");
                wharfIn.setText(shiftDataList.get(position).getArriveShipDockName() + "");
//                addShiftsInfoRequsetBean.setRouteId(shiftDataList.get(position).getRouteId());
                popupWindow.dismiss();
            }
        });

        popupWindow.showAtLocation(llLineSelete, Gravity.BOTTOM | Gravity.CENTER_VERTICAL, 0, 0);

        popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                popupWindow.backgroundAlpha(ChangeBanCiActivity.this, 1f);
            }
        });
    }


    private void showdata(String from) {

        DatePicker datePicker = new DatePicker(ChangeBanCiActivity.this);

        datePicker.setOnCancelClickListener(view1 -> datePicker.dismiss())
                //“确定”的点击事件
                .setOnConfirmClickListener(view12 -> {
                    if (from.equals("begin")) {
                        startDate = datePicker.getSelectedYear() + "-" + datePicker.getSelectedMonth() + "-" + datePicker.getSelectedDay();
                        //对比时间，开始时间要比结束时间早
                        if (!StringUtil.isNullOrEmpty(startDate) && !StringUtil.isNullOrEmpty(endDate)) {
                            if (TimeUtil.compareTime(startDate, endDate)) {
                                beginData.setText(startDate);
//                                addShiftsInfoRequsetBean.setStartDate(startDate);
                            } else {
                                beginData.setText("");
                                ToastUtil.showToast("结束时间应大于开始时间，请重新设置");
                            }
                        } else {
                            beginData.setText(startDate);
//                            addShiftsInfoRequsetBean.setStartDate(startDate);
                        }
                    } else {
                        endDate = datePicker.getSelectedYear() + "-" + datePicker.getSelectedMonth() + "-" + datePicker.getSelectedDay();
                        //对比时间，开始时间要比结束时间早
                        if (!StringUtil.isNullOrEmpty(startDate) && !StringUtil.isNullOrEmpty(endDate)) {
                            if (TimeUtil.compareTime(startDate, endDate)) {
                                endData.setText(endDate);
//                                addShiftsInfoRequsetBean.setEndDate(endDate);
                            } else {
                                endData.setText("");
                                ToastUtil.showToast("结束时间应大于开始时间，请重新设置");
                            }
                        } else {
                            endData.setText(endDate);
//                            addShiftsInfoRequsetBean.setEndDate(endDate);
                        }

                    }

                    datePicker.dismiss();
                })
                //“取消”、“确定”的文字颜色
                .setColorConfirm(Color.BLUE)
                .setColorCancel(Color.BLACK)

                //选择“时间”的显示样式
                .setDateShowStyle(DatePicker.DATE_SHOW_STYLE_3)

                // 左右箭头颜色
                .setColorLeftArrow(Color.DKGRAY)
                .setColorRightArrow(Color.DKGRAY)

                //星期的颜色
                .setColorWeeks(DatePicker.SUNDAY, Color.DKGRAY)

                //“今天”以前、今天、“今天”以后 的显示文字颜色
                .setColorFontBeforeToday(Color.LTGRAY)
                .setColorFontToday(Color.WHITE)
                .setColorFontAfterToday(Color.BLACK)

                //“今天”的背景颜色
                .setColorBgdToday(Color.GRAY)
                //选中日期的文字颜色和背景颜色
                .setColorFontSelectedDay(Color.WHITE)
                .setColorBgdSelectedDay(Color.DKGRAY)
                .show();

    }


    private void showNoTimedata(String from) {

        DatePicker datePicker = new DatePicker(ChangeBanCiActivity.this);

        datePicker.setOnCancelClickListener(view1 -> datePicker.dismiss())
                //“确定”的点击事件
                .setOnConfirmClickListener(view12 -> {
                    if (from.equals("begin")) {
                        startNoDate = datePicker.getSelectedYear() + "-" + datePicker.getSelectedMonth() + "-" + datePicker.getSelectedDay();
                        //对比时间，开始时间要比结束时间早
                        if (!StringUtil.isNullOrEmpty(startNoDate) && !StringUtil.isNullOrEmpty(endNoDate)) {
                            if (TimeUtil.compareTime(startNoDate, endNoDate)) {
                                noTimeBegin.setText(startNoDate);
                            } else {
                                noTimeBegin.setText("");
                                ToastUtil.showToast("结束时间应大于开始时间，请重新设置");
                            }
                        } else {
                            noTimeBegin.setText(startNoDate);
                        }
                    } else {
                        endNoDate = datePicker.getSelectedYear() + "-" + datePicker.getSelectedMonth() + "-" + datePicker.getSelectedDay();
                        //对比时间，开始时间要比结束时间早
                        if (!StringUtil.isNullOrEmpty(startNoDate) && !StringUtil.isNullOrEmpty(endNoDate)) {
                            if (TimeUtil.compareTime(startNoDate, endNoDate)) {
                                noTimeEnd.setText(endNoDate);
                            } else {
                                noTimeEnd.setText("");
                                ToastUtil.showToast("结束时间应大于开始时间，请重新设置");
                            }
                        } else {
                            noTimeEnd.setText(endNoDate);
                        }

                    }

                    datePicker.dismiss();
                })
                //“取消”、“确定”的文字颜色
                .setColorConfirm(Color.BLUE)
                .setColorCancel(Color.BLACK)

                //选择“时间”的显示样式
                .setDateShowStyle(DatePicker.DATE_SHOW_STYLE_3)

                // 左右箭头颜色
                .setColorLeftArrow(Color.DKGRAY)
                .setColorRightArrow(Color.DKGRAY)

                //星期的颜色
                .setColorWeeks(DatePicker.SUNDAY, Color.DKGRAY)

                //“今天”以前、今天、“今天”以后 的显示文字颜色
                .setColorFontBeforeToday(Color.LTGRAY)
                .setColorFontToday(Color.WHITE)
                .setColorFontAfterToday(Color.BLACK)

                //“今天”的背景颜色
                .setColorBgdToday(Color.GRAY)
                //选中日期的文字颜色和背景颜色
                .setColorFontSelectedDay(Color.WHITE)
                .setColorBgdSelectedDay(Color.DKGRAY)
                .show();

    }
}
